package cn.itcast.order.web;

import cn.itcast.order.client.StorageClient;
import cn.itcast.order.client.vo.StorageVO;
import cn.itcast.order.entity.Order;
import cn.itcast.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 虎哥
 */
@RestController
@RequestMapping("order")
public class OrderController {

    private final OrderService orderService;

    public OrderController(OrderService orderService) {
        this.orderService = orderService;
    }

    @Autowired
    private StorageClient storageClient;

    /**
     * @Description: 下订单
     * @param order
     * @return org.springframework.http.ResponseEntity<java.lang.Long>
     */
    @PostMapping
    public ResponseEntity<Long> createOrder(Order order){
        Long orderId = orderService.create(order);
        return ResponseEntity.status(HttpStatus.CREATED).body(orderId);
    }

    /**
     * @Description: 验证feign接口调用如何优雅定义返回对象
     * @return org.springframework.http.ResponseEntity<java.lang.Long>
     */
    @GetMapping("/testOpenfeignReturnVo")
    public String testOpenfeignReturnVo(){
        String commodityCode = "100202003032041";
        StorageVO storageVO = storageClient.getStorageInfoByCommodityCode(commodityCode);
        System.out.println(storageVO.toString());
        return "请求成功！";
    }
}
